package pacman;

import java.util.ArrayList;
/**
 * This is a iFood-interface implementing class. Fish.
 */
public class cFish implements iFood {
    
    private Position position;
    private cCore parent;
    
    /**
     * Creates a new instance of cFish.
     * @param position The position where the fish should be placed.
     * @param parent The core of the game where the fish should be placed. Needed for placement reasons.
     */
    public cFish(Position position, cCore parent) {
        this.position=position;
        this.parent=parent;
    }

    /**
     * Returns the current position of fish.
     * @return The current position of fish.
     */
    public Position getPosition() {
        return position;
    }

    /**
     * Does an access to the fish (i.e. tells the fish that it's been eaten, and tells the pacman that it he has eaten a fish)
     * @param pacman The pacman who eats the fish.
     */
    public void Eat(cPacman pacman) {
        pacman.setPoints(pacman.getPoints()+10);
        
        ArrayList<iFood> FoodList=parent.getFoodList();
        int HasFish=0;
        for(int i=0;i<FoodList.size();i++){
            if(FoodList.get(i).getImageName().equals(this.getImageName())){
                HasFish++;
            }
        }
        if(HasFish==1){
            parent.Win();
        }
    }

    /**
     * Gives the fish a new position.
     * @param pos The new position of the fish.
     */
    public void setPosition(Position pos) {
        this.position=pos;
    }
    
    /**
     * Returns the name of the image to be loaded for this fish.
     * @return A string containing the name of the image to be loaded for this fish.
     */
    public String getImageName(){
        return "fish";
    }
}
